const axios = require('axios');
const MockAdapter = require('axios-mock-adapter');
const normalAxios = axios.create();
const mockAxios = axios.create();
import { jsonToTree } from "../utils/tools";
import Config from "./config";
import reqTools from "../utils/reqTools";
import conf from "../utils/config";

// mock 数据
var mock = new MockAdapter(mockAxios);

mock.onPut('/bindingEmail').reply((config) => {
  return new Promise(function (resolve, reject) {
    reqTools.put('/api/sysUser/modifyBinding',
      config.data,
      { headers: { 'Content-Type': 'application/json' } }
    ).then((res) => {
      resolve([200, res]);
    }).catch((err) => {
      reject([500, err]);
    });
  });
});

mock.onGet('/verifyingmailbox').reply((config) => {
  return new Promise(function(resolve, reject) {
    reqTools.get('/api/sysUser/verifyingmailbox',
    {
      email:config.email
    }
    ).then((res) => {
      resolve([200, res]);
    }).catch((err) => {
      resolve([500, err ]);
    });
  });

});



mock.onGet('/getCaptcha').reply((config) => {
  return new Promise((resolve, reject) => {
    mockAxios.get(conf.primary + "/api/sysUser/getCaptchaBind", config).then((res) => {
      resolve([res.status, res.data]);
    }).catch((err) => {
      reject(err);
    });
  });
});

mock.onPut('/validMailCode').reply((config) => {
  return new Promise(function (resolve, reject) {
    reqTools.put('/api/sysUser/validMailCodeBind',
      config.data,
      { headers: { 'Content-Type': 'application/json' } }
    ).then((res) => {
      resolve([200, res]);
    }).catch((err) => {
      reject([500, err]);
    });
  });
});

mock.onPost('/sendMailbind').reply((config) => {
  return new Promise(function(resolve, reject) { 
    reqTools.post('/api/sysUser/sendMailbind', config.data).then((res) => {
     resolve([200, res ]);
   }).catch((err) => {
     resolve([500, err ]);
   });
 });
});
export default mockAxios;
